/*
 *
 *    Copyright (c) 2022 Project CHIP Authors
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

// THIS FILE IS GENERATED BY ZAP
// This file is generated from clusters-Structs.ipp.zapt

#include <clusters/ThreadNetworkDiagnostics/Structs.h>

#include <app/data-model/StructDecodeIterator.h>
#include <app/data-model/WrappedStructEncoder.h>

namespace chip {
namespace app {
namespace Clusters {
namespace ThreadNetworkDiagnostics {
namespace Structs {

namespace NeighborTableStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kExtAddress), extAddress);
    encoder.Encode(to_underlying(Fields::kAge), age);
    encoder.Encode(to_underlying(Fields::kRloc16), rloc16);
    encoder.Encode(to_underlying(Fields::kLinkFrameCounter), linkFrameCounter);
    encoder.Encode(to_underlying(Fields::kMleFrameCounter), mleFrameCounter);
    encoder.Encode(to_underlying(Fields::kLqi), lqi);
    encoder.Encode(to_underlying(Fields::kAverageRssi), averageRssi);
    encoder.Encode(to_underlying(Fields::kLastRssi), lastRssi);
    encoder.Encode(to_underlying(Fields::kFrameErrorRate), frameErrorRate);
    encoder.Encode(to_underlying(Fields::kMessageErrorRate), messageErrorRate);
    encoder.Encode(to_underlying(Fields::kRxOnWhenIdle), rxOnWhenIdle);
    encoder.Encode(to_underlying(Fields::kFullThreadDevice), fullThreadDevice);
    encoder.Encode(to_underlying(Fields::kFullNetworkData), fullNetworkData);
    encoder.Encode(to_underlying(Fields::kIsChild), isChild);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kExtAddress))
        {
            err = DataModel::Decode(reader, extAddress);
        }
        else if (__context_tag == to_underlying(Fields::kAge))
        {
            err = DataModel::Decode(reader, age);
        }
        else if (__context_tag == to_underlying(Fields::kRloc16))
        {
            err = DataModel::Decode(reader, rloc16);
        }
        else if (__context_tag == to_underlying(Fields::kLinkFrameCounter))
        {
            err = DataModel::Decode(reader, linkFrameCounter);
        }
        else if (__context_tag == to_underlying(Fields::kMleFrameCounter))
        {
            err = DataModel::Decode(reader, mleFrameCounter);
        }
        else if (__context_tag == to_underlying(Fields::kLqi))
        {
            err = DataModel::Decode(reader, lqi);
        }
        else if (__context_tag == to_underlying(Fields::kAverageRssi))
        {
            err = DataModel::Decode(reader, averageRssi);
        }
        else if (__context_tag == to_underlying(Fields::kLastRssi))
        {
            err = DataModel::Decode(reader, lastRssi);
        }
        else if (__context_tag == to_underlying(Fields::kFrameErrorRate))
        {
            err = DataModel::Decode(reader, frameErrorRate);
        }
        else if (__context_tag == to_underlying(Fields::kMessageErrorRate))
        {
            err = DataModel::Decode(reader, messageErrorRate);
        }
        else if (__context_tag == to_underlying(Fields::kRxOnWhenIdle))
        {
            err = DataModel::Decode(reader, rxOnWhenIdle);
        }
        else if (__context_tag == to_underlying(Fields::kFullThreadDevice))
        {
            err = DataModel::Decode(reader, fullThreadDevice);
        }
        else if (__context_tag == to_underlying(Fields::kFullNetworkData))
        {
            err = DataModel::Decode(reader, fullNetworkData);
        }
        else if (__context_tag == to_underlying(Fields::kIsChild))
        {
            err = DataModel::Decode(reader, isChild);
        }

        ReturnErrorOnFailure(err);
    }
}

} // namespace NeighborTableStruct

namespace OperationalDatasetComponents {
CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kActiveTimestampPresent), activeTimestampPresent);
    encoder.Encode(to_underlying(Fields::kPendingTimestampPresent), pendingTimestampPresent);
    encoder.Encode(to_underlying(Fields::kMasterKeyPresent), masterKeyPresent);
    encoder.Encode(to_underlying(Fields::kNetworkNamePresent), networkNamePresent);
    encoder.Encode(to_underlying(Fields::kExtendedPanIdPresent), extendedPanIdPresent);
    encoder.Encode(to_underlying(Fields::kMeshLocalPrefixPresent), meshLocalPrefixPresent);
    encoder.Encode(to_underlying(Fields::kDelayPresent), delayPresent);
    encoder.Encode(to_underlying(Fields::kPanIdPresent), panIdPresent);
    encoder.Encode(to_underlying(Fields::kChannelPresent), channelPresent);
    encoder.Encode(to_underlying(Fields::kPskcPresent), pskcPresent);
    encoder.Encode(to_underlying(Fields::kSecurityPolicyPresent), securityPolicyPresent);
    encoder.Encode(to_underlying(Fields::kChannelMaskPresent), channelMaskPresent);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kActiveTimestampPresent))
        {
            err = DataModel::Decode(reader, activeTimestampPresent);
        }
        else if (__context_tag == to_underlying(Fields::kPendingTimestampPresent))
        {
            err = DataModel::Decode(reader, pendingTimestampPresent);
        }
        else if (__context_tag == to_underlying(Fields::kMasterKeyPresent))
        {
            err = DataModel::Decode(reader, masterKeyPresent);
        }
        else if (__context_tag == to_underlying(Fields::kNetworkNamePresent))
        {
            err = DataModel::Decode(reader, networkNamePresent);
        }
        else if (__context_tag == to_underlying(Fields::kExtendedPanIdPresent))
        {
            err = DataModel::Decode(reader, extendedPanIdPresent);
        }
        else if (__context_tag == to_underlying(Fields::kMeshLocalPrefixPresent))
        {
            err = DataModel::Decode(reader, meshLocalPrefixPresent);
        }
        else if (__context_tag == to_underlying(Fields::kDelayPresent))
        {
            err = DataModel::Decode(reader, delayPresent);
        }
        else if (__context_tag == to_underlying(Fields::kPanIdPresent))
        {
            err = DataModel::Decode(reader, panIdPresent);
        }
        else if (__context_tag == to_underlying(Fields::kChannelPresent))
        {
            err = DataModel::Decode(reader, channelPresent);
        }
        else if (__context_tag == to_underlying(Fields::kPskcPresent))
        {
            err = DataModel::Decode(reader, pskcPresent);
        }
        else if (__context_tag == to_underlying(Fields::kSecurityPolicyPresent))
        {
            err = DataModel::Decode(reader, securityPolicyPresent);
        }
        else if (__context_tag == to_underlying(Fields::kChannelMaskPresent))
        {
            err = DataModel::Decode(reader, channelMaskPresent);
        }

        ReturnErrorOnFailure(err);
    }
}

} // namespace OperationalDatasetComponents

namespace RouteTableStruct {
CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kExtAddress), extAddress);
    encoder.Encode(to_underlying(Fields::kRloc16), rloc16);
    encoder.Encode(to_underlying(Fields::kRouterId), routerId);
    encoder.Encode(to_underlying(Fields::kNextHop), nextHop);
    encoder.Encode(to_underlying(Fields::kPathCost), pathCost);
    encoder.Encode(to_underlying(Fields::kLQIIn), LQIIn);
    encoder.Encode(to_underlying(Fields::kLQIOut), LQIOut);
    encoder.Encode(to_underlying(Fields::kAge), age);
    encoder.Encode(to_underlying(Fields::kAllocated), allocated);
    encoder.Encode(to_underlying(Fields::kLinkEstablished), linkEstablished);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kExtAddress))
        {
            err = DataModel::Decode(reader, extAddress);
        }
        else if (__context_tag == to_underlying(Fields::kRloc16))
        {
            err = DataModel::Decode(reader, rloc16);
        }
        else if (__context_tag == to_underlying(Fields::kRouterId))
        {
            err = DataModel::Decode(reader, routerId);
        }
        else if (__context_tag == to_underlying(Fields::kNextHop))
        {
            err = DataModel::Decode(reader, nextHop);
        }
        else if (__context_tag == to_underlying(Fields::kPathCost))
        {
            err = DataModel::Decode(reader, pathCost);
        }
        else if (__context_tag == to_underlying(Fields::kLQIIn))
        {
            err = DataModel::Decode(reader, LQIIn);
        }
        else if (__context_tag == to_underlying(Fields::kLQIOut))
        {
            err = DataModel::Decode(reader, LQIOut);
        }
        else if (__context_tag == to_underlying(Fields::kAge))
        {
            err = DataModel::Decode(reader, age);
        }
        else if (__context_tag == to_underlying(Fields::kAllocated))
        {
            err = DataModel::Decode(reader, allocated);
        }
        else if (__context_tag == to_underlying(Fields::kLinkEstablished))
        {
            err = DataModel::Decode(reader, linkEstablished);
        }

        ReturnErrorOnFailure(err);
    }
}

} // namespace RouteTableStruct

namespace SecurityPolicy {
CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
{
    DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
    encoder.Encode(to_underlying(Fields::kRotationTime), rotationTime);
    encoder.Encode(to_underlying(Fields::kFlags), flags);
    return encoder.Finalize();
}

CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
{
    detail::StructDecodeIterator __iterator(reader);
    while (true)
    {
        uint8_t __context_tag = 0;
        CHIP_ERROR err        = __iterator.Next(__context_tag);
        VerifyOrReturnError(err != CHIP_ERROR_END_OF_TLV, CHIP_NO_ERROR);
        ReturnErrorOnFailure(err);

        if (__context_tag == to_underlying(Fields::kRotationTime))
        {
            err = DataModel::Decode(reader, rotationTime);
        }
        else if (__context_tag == to_underlying(Fields::kFlags))
        {
            err = DataModel::Decode(reader, flags);
        }

        ReturnErrorOnFailure(err);
    }
}

} // namespace SecurityPolicy
} // namespace Structs
} // namespace ThreadNetworkDiagnostics
} // namespace Clusters
} // namespace app
} // namespace chip
